package com.ruoyi.project.channel.smsInfo.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.channel.smsInfo.domain.SmsInfo;
import com.ruoyi.project.channel.smsInfo.service.ISmsInfoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 短信信息操作处理
 * 
 * @author CAIN
 * @date 2019-10-26
 */
@Controller
@RequestMapping("/channel/smsInfo")
public class SmsInfoController extends BaseController
{
    private String prefix = "channel/smsInfo";
	
	@Autowired
	private ISmsInfoService smsInfoService;
	
	@RequiresPermissions("channel:smsInfo:view")
	@GetMapping()
	public String smsInfo()
	{
	    return prefix + "/smsInfo";
	}
	
	/**
	 * 查询短信列表
	 */
	@RequiresPermissions("channel:smsInfo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(SmsInfo smsInfo)
	{
		startPage();
        List<SmsInfo> list = smsInfoService.selectSmsInfoList(smsInfo);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出短信列表
	 */
	@RequiresPermissions("channel:smsInfo:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SmsInfo smsInfo)
    {
    	List<SmsInfo> list = smsInfoService.selectSmsInfoList(smsInfo);
        ExcelUtil<SmsInfo> util = new ExcelUtil<SmsInfo>(SmsInfo.class);
        return util.exportExcel(list, "smsInfo");
    }
	
	/**
	 * 新增短信
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存短信
	 */
	@RequiresPermissions("channel:smsInfo:add")
	@Log(title = "短信", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(SmsInfo smsInfo)
	{		
		return toAjax(smsInfoService.insertSmsInfo(smsInfo));
	}

	/**
	 * 修改短信
	 */
	@GetMapping("/edit/{smsId}")
	public String edit(@PathVariable("smsId") Long smsId, ModelMap mmap)
	{
		SmsInfo smsInfo = smsInfoService.selectSmsInfoById(smsId);
		mmap.put("smsInfo", smsInfo);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存短信
	 */
	@RequiresPermissions("channel:smsInfo:edit")
	@Log(title = "短信", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(SmsInfo smsInfo)
	{		
		return toAjax(smsInfoService.updateSmsInfo(smsInfo));
	}
	
	/**
	 * 删除短信
	 */
	@RequiresPermissions("channel:smsInfo:remove")
	@Log(title = "短信", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(smsInfoService.deleteSmsInfoByIds(ids));
	}
	
}
